Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): calling CheckPoint::insert with existing block must succeed #1601

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Sep 12, 2024

Description

Previously, we were panicking when the caller tried to insert a block at height 0. However, this should succeed if the block hash does not change.

Notes to the reviewers

For context:

Changelog notice

  • Fix CheckPoint::insert to not panic when inserting existing genesis block (same block height and hash).

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Bugfixes:

* [ ] This pull request breaks the existing API

  • I've added tests to reproduce the issue which are now passing

tnull added a commit to tnull/ldk-node that referenced this pull request Sep 12, 2024
BDK currently panics if we start syncing the node while the
tip height is still 0, which happens in our usual regtest setup.

Here, we make sure to premine *before* starting up the nodes to avoid
hitting this panic. While splitting premining and distributing funds in
this way is fine (and even makes sense) in most cases, in some cases
it's annoying as we wouldn't previously premine at all, but are now
required to. So we should eventually drop/revert (at least this part of)
this workaround as soon as BDK ships the fix on their end
(bitcoindevkit/bdk#1601).
tnull added a commit to tnull/ldk-node that referenced this pull request Sep 12, 2024
BDK currently panics if we start syncing the node while the
tip height is still 0, which happens in our usual regtest setup.

Here, we make sure to premine *before* starting up the nodes to avoid
hitting this panic. While splitting premining and distributing funds in
this way is fine (and even makes sense) in most cases, in some cases
it's annoying as we wouldn't previously premine at all, but are now
required to. So we should eventually drop/revert (at least this part of)
this workaround as soon as BDK ships the fix on their end
(bitcoindevkit/bdk#1601).
tnull added a commit to tnull/ldk-node that referenced this pull request Sep 12, 2024
BDK currently panics if we start syncing the node while the
tip height is still 0, which happens in our usual regtest setup.

Here, we make sure to premine *before* starting up the nodes to avoid
hitting this panic. While splitting premining and distributing funds in
this way is fine (and even makes sense) in most cases, in some cases
it's annoying as we wouldn't previously premine at all, but are now
required to. So we should eventually drop/revert (at least this part of)
this workaround as soon as BDK ships the fix on their end
(bitcoindevkit/bdk#1601).
@evanlinjin evanlinjin marked this pull request as ready for review September 12, 2024 10:13
@evanlinjin evanlinjin self-assigned this Sep 12, 2024
@evanlinjin evanlinjin added the bug Something isn't working label Sep 12, 2024
@evanlinjin evanlinjin added this to the 1.0.0-beta milestone Sep 12, 2024
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

crates/core/tests/test_checkpoint.rs Outdated Show resolved Hide resolved
crates/core/tests/test_checkpoint.rs Outdated Show resolved Hide resolved
Previously, we were panicking when the caller tried to insert a block at
height 0. However, this should succeed if the block hash does not
change.
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2970b83

@LagginTimes
Copy link
Contributor

ACK 2970b83

Copy link
Contributor

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a fine solution but ideally we should ensure bdk never calls CheckPoint::insert with a block height of 0 for example in electrum and esplora (still looking for a way to reproduce it).

We can add a Panics section to the docs, something like

/// # Panics
///
/// This panics if called with a genesis block that differs from that of `self`.

let cp_chain = CheckPoint::from_block_ids(blocks[..=i].iter().copied())
.expect("must construct valid chain");

for j in 0..i {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for j in 0..i {
for j in 0..=i {

Copy link
Contributor

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self ACK 3ae9ecb

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 3ae9ecb

@notmandatory notmandatory merged commit 6d610bf into bitcoindevkit:master Sep 12, 2024
21 checks passed
tnull added a commit to tnull/ldk-node that referenced this pull request Sep 13, 2024
BDK currently panics if we start syncing the node while the
tip height is still 0, which happens in our usual regtest setup.

Here, we make sure to premine *before* starting up the nodes to avoid
hitting this panic. While splitting premining and distributing funds in
this way is fine (and even makes sense) in most cases, in some cases
it's annoying as we wouldn't previously premine at all, but are now
required to. So we should eventually drop/revert (at least this part of)
this workaround as soon as BDK ships the fix on their end
(bitcoindevkit/bdk#1601).
This was referenced Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants